package cn.kuick.match10.test1;

import java.util.Scanner;
import java.util.regex.Pattern;

public class DateFormat {

	private static Pattern SEP_PATTERN = Pattern.compile("[-|\\/|:]");
	private static String AM = "am";
	private static String PM = "pm";
	
	public String convert(String text) {
		Scanner scanner = new Scanner(text);
		scanner.useDelimiter(SEP_PATTERN);
		
		int year,mon,day,hour,mini,sec;
		String sign = AM;
		
		try {
			// year
			year = scanner.nextInt();
			
			// mon
			mon = scanner.nextInt();
			
			// day
			day = scanner.nextInt();
			
			// hour
			hour = scanner.nextInt();
			
			// mini
			mini = scanner.nextInt();
			
			// sec
			sec = scanner.nextInt();
			
	        
			// AM or PM
	        if(hour == 0) {
	            hour = 12;
	        } else if(hour >= 12) {
	            if(hour > 12)
	                hour -= 12;
	            sign = PM;
	        }
		} finally {
			scanner.close();
		}
		
        return String.format("%d%d/%d%d/%d-%d%d:%d%d:%d%d%s",mon/10,mon%10,day/10,day%10,year,hour/10,hour%10,mini/10,mini%10,sec/10,sec%10,sign);
	}
}
